import Common from '../../../common/common.js';
let common = new Common;
const app = getApp();

Page({
  data: {
    isSignEnd:false,//报名截止
    isEnd:0,
    liveActivityInfo: "",
    zbPlanGoods: [], //总部商品库 
  },
  onLoad: function (options) {
    let isEnd = Number(options.isEnd);
    this.setData({
      isEnd
    })
  },
  onReady: function () {},
  onShow: function () {
    if(this.data.isEnd){
      //已结束的直播活动
      this.setData({
        liveActivityInfo:getApp().globalData.liveActivityInfo
      })
      getApp().globalData.liveActivityInfo=''
    }else{
      this.getLiveActivity()
    }
  },
  /**
   * 获取直播活动详情
   * 店长且有活动的情况下开放入口
   * **/
  getLiveActivity() {
    common.requestAjax("/api/flashsale-service/v1/zbRelatedApi/getZbEntrance", "GET", {
      orgSeq: app.globalData.orgSeq
    }).then(res => {
      this.setData({
        liveActivityInfo: res.data.result || ""
      })
      this.getZbPlanGoods();

      if(res.data.code==0&&this.data.liveActivityInfo.approvalStatus==0){
        this.setData({
          isSignEnd:true
        })
      }
    })
  },
  //查询总部商品库列表
  getZbPlanGoods() {
    common.requestAjax("/api/flashsale-service/v1/zbRelatedApi/zbPlanInfo", "GET", {
      planId: this.data.liveActivityInfo.planId,
      orgSeq:app.globalData.shopInfo.orgSeq
    }).then(res => {
      if (res.data.code) {
        let arrayList = [];
        arrayList = res.data.result.zbPlanGoods.forEach(element => {
          if (element.auditStatus == 2) {
            return element
          }
        })
        this.setData({
          zbPlanGoods: arrayList
        })
      }
    })
  },
  gotoCreate() {
    wx.navigateTo({
      url: `/pages/myCenter/liveActivity/creatStep/index?activityId=${this.data.liveActivityInfo.planId}&uuid=${this.data.liveActivityInfo.uuid}`,
    })
  },
  gotoReBuild() {
    wx.navigateTo({
      url: `/pages/myCenter/liveActivity/creatStep/index?activityId=${this.data.liveActivityInfo.planId}&uuid=${this.data.liveActivityInfo.zbHomeDTOList[0].uuid}&isEdit=1`,
    })
  }
})